package com.yserp.project.erp.basic.warehouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yserp.common.constant.Constants;
import com.yserp.common.utils.mybatis.MybatisPlusUtil;
import com.yserp.common.utils.text.Convert;
import com.yserp.project.erp.basic.warehouse.domain.BasisWarehouse;
import com.yserp.project.erp.basic.warehouse.mapper.BasisWarehouseMapper;
import com.yserp.project.erp.basic.warehouse.service.IBasisWarehouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 仓库管理Service业务层处理
 * 
 * @author yserp
 * @date 2022-06-29
 */
@Service
public class BasisWarehouseServiceImpl extends ServiceImpl<BasisWarehouseMapper,BasisWarehouse> implements IBasisWarehouseService
{
    @Resource
    private BasisWarehouseMapper basisWarehouseMapper;

    /**
     * 查询仓库管理
     * 
     * @param id 仓库管理主键
     * @return 仓库管理
     */
    @Override
    public BasisWarehouse selectBasisWarehouseById(Long id)
    {
        return basisWarehouseMapper.selectById(id);
    }

    /**
     * 查询仓库管理列表
     * 
     * @param basisWarehouse 仓库管理
     * @return 仓库管理
     */
    @Override
    public List<BasisWarehouse> selectBasisWarehouseList(BasisWarehouse basisWarehouse)
    {
        QueryWrapper<BasisWarehouse> queryWrapper = new QueryWrapper<>();
        MybatisPlusUtil.notNullField(basisWarehouse,queryWrapper);
        return basisWarehouseMapper.selectList(queryWrapper);
    }

    /**
     * 新增仓库管理
     * 
     * @param basisWarehouse 仓库管理
     * @return 结果
     */
    @Override
    public int insertBasisWarehouse(BasisWarehouse basisWarehouse)
    {
        return basisWarehouseMapper.insert(basisWarehouse);
    }

    /**
     * 修改仓库管理
     * 
     * @param basisWarehouse 仓库管理
     * @return 结果
     */
    @Override
    public int updateBasisWarehouse(BasisWarehouse basisWarehouse)
    {
        return basisWarehouseMapper.updateById(basisWarehouse);
    }

    /**
     * 批量删除仓库管理
     * 
     * @param ids 需要删除的仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteBasisWarehouseByIds(String ids)
    {
        return basisWarehouseMapper.deleteBatchIds(Arrays.asList(Convert.toStrArray(ids)));
    }

    /**
     * 删除仓库管理信息
     * 
     * @param id 仓库管理主键
     * @return 结果
     */
    @Override
    public int deleteBasisWarehouseById(Long id) {
        return basisWarehouseMapper.deleteById(id);
    }

    @Override
    public String checkWarehouseCodeUnique(String warehouseCode) {
        String flag = Constants.NAME_UNIQUE;
        int count = basisWarehouseMapper.selectCount(new QueryWrapper<BasisWarehouse>().eq("warehouse_code",warehouseCode));
        if (count > 0) {
            flag = Constants.NAME_NOT_UNIQUE;
        }
        return flag;
    }
}
